/*
 * rosa_task.c
 *
 * Created: 2014-12-17 10:11:48
 *  Author: Andreas Domfors
 */ 
#include <malloc.h>
#include <string.h>
#include "kernel/rosa_task.h"

/// Dynamically allocates memory for a new task
tcb *allocateTask(unsigned int stackSize)
{
	tcb *task = malloc(sizeof(tcb));
	if(task == NULL)
		return NULL;
		
	task->dataarea = malloc(stackSize + STACK_MARGIN);
	if(task->dataarea == NULL)
	{
		free(task);
		return NULL;
	}
	
	memset(task->dataarea, 0xCC, stackSize + STACK_MARGIN);
	task->datasize = stackSize;
	return task;
}

/// Frees the memory associated with a task
void freeTask(tcb *task)
{
	free(task->dataarea);
	free(task);
}
